home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group00b.txt / 000102_icon-group-sender_Tue Oct 24 16:47:28 2000.msg < prev    next >
Internet Message Format  |  2001-01-03  |  3KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id e9ONlLP25739
  4.     for icon-group-addresses; Tue, 24 Oct 2000 16:47:21 -0700 (MST)
  5. Message-Id: <200010242347.e9ONlLP25739@baskerville.CS.Arizona.EDU>
  6. Date: Tue, 24 Oct 2000 13:59:26 -0700
  7. From: Steve Wampler <swampler@noao.edu>
  8. X-Accept-Language: en
  9. To: symbiot@my-deja.com, icon-group <icon-group@cs.arizona.edu>
  10. Subject: Re: How to "declare" a string?
  11. Errors-To: icon-group-errors@cs.arizona.edu
  12. Status: RO
  13. Content-Length: 2048
  14.  
  15. symbiot@my-deja.com wrote:
  16. > Hi,
  17. > Thanks for your response.
  18. > I based my program on the same assumption you made concerning how ICON
  19. > scan variables and assigns type according to usage (and even converts
  20. > on the fly).
  21. > But in the statement I listed, it seemed to barf because I was
  22. > requiring it to create an indexed string.
  23. > The line was, essentially,
  24. > data[index] := .....results of some string operation....
  25. > I even tried intially data with
  26. > data := " "
  27. > But that created a variable that was one cell in size. So when the
  28. > abouve statement got to "index := 2", it barfed because the variable
  29. > data wasn't large enough.
  30. > So again I'm back to the quesiton, "How to 'declare' a string variable?"
  31.  
  32. There's probably some confusion over terminology here.  There is no
  33. such thing as a "string variable" in Icon (or an "integer variable",
  34. nor any other "typed" variable.
  35.  
  36. Any variable in Icon can hold a value of any type.  Think of a variable
  37. as a bucket that you can place anything in.  Initially it's empty,
  38. so trying to subscript it generates an error because there nothing
  39. there to subscript it.  Similarly, when you put the (1-character long)
  40. string " " into it, subscripting failed when you tried to go past the
  41. end of the string.
  42.  
  43. You could, of course, put a much larger string into the variable. There
  44. are any number of ways to do so, for example:
  45.  
  46.    data := repl(" ",4096)
  47.  
  48. would put a string of 4,096 blanks into data.
  49.  
  50. However, that's probably not the best way to make use of Icon, it leads
  51. to thinking in terms of the variables instead of the values themselves,
  52. and generally results in more complicated code than is necessary.
  53.  
  54. You might try and rethink how you're approaching the problem and think
  55. more in terms of what you want the resulting value to look like and how
  56. you might transform the input value into that result.  Several people
  57. have made some good suggestions on how you might proceed in this way.
  58.  
  59. --
  60. Steve Wampler-  SOLIS Project, National Solar Observatory
  61. swampler@noao.edu
  62.